/*
 * @Copyright: Copyright (c) 2019
 * @Author: 一枚小工
 * @Version: 1.0
 * @Date: 2019-10-25 18:14:45
 */
import { _decorator, Component, Node, RigidBodyComponent, PhysicMaterial, ColliderComponent } from "cc";
const { ccclass, property } = _decorator;

@ccclass("PhyMat")
export class PhyMat extends Component {
    
    @property
    private friction: number = 0; // 摩擦力

    @property
    private restitution: number = 0; // 弹力
    
    /* class member could be defined like this */
    // dummy = '';

    /* use `property` decorator if your want the member to be serializable */
    // @property
    // serializableDummy = 0;

    onLoad(): void{
        let comps: Array<ColliderComponent> = this.node.getComponents(ColliderComponent) as Array<ColliderComponent>;

        let mat = new PhysicMaterial();
        mat.friction = this.friction;
        mat.restitution = this.restitution;

        for(let i = 0; i < comps.length; i++){
            comps[i].material = mat;
        }
    }

    start () {
        // Your initialization goes here.
        
    }

    // update (deltaTime: number) {
    //     // Your update function goes here.
    // }
}
